<template>
  <div class="back"></div>
  <div class="body">
    <div id="content">
      <p style="text-align: center; font-size: 60px; font-family: 华文行楷">
        抒 后台管理系统
      </p>
      <div id="son">
        <span id="input">
          <a-input v-model:value="UserName" placeholder="请输入账户" />
        </span>
        <span id="input">
          <a-input-password v-model:value="PassWord" placeholder="请输入密码" />
        </span>
        <a-button
          id="btn"
          type="primary"
          ghost
          style="margin-top: 30px; margin-left: 40%"
          @click="doLogin()"
        >
          登录
        </a-button>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from "vue";
import { message } from "ant-design-vue";
import { dologin } from "../api/login";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import io from "./units/socket.js";

export default defineComponent({
  setup() {
    const router = useRouter();
    const store = useStore();
    const UserName = ref("");
    const PassWord = ref("");

    const doLogin = () => {
      if (UserName.value == "" || PassWord.value == "") {
        message.info("账户密码不能为空");
      } else {
        dologin({
          url: "/admin/dologin",
          username: UserName.value,
          password: PassWord.value,
          success: (res) => {
            // console.log(res.data);
            message.info(res.data.data);
            store.dispatch("setUser", true);
            sessionStorage.setItem("Flag", "loginType");
            sessionStorage.setItem("name", res.data.name);
            io.emit("login", { aid: res.data.aid });
            router.push({ path: "/home" });
          },
          err: (err) => {
            console.log(err);
          },
        });
      }
    };

    return {
      UserName,
      PassWord,
      doLogin,
    };
  },

  components: {},
});
</script>

<style socped>
.back {
  background: url("../assets/images/12580.jpeg") no-repeat;
  background-position: center;
  background-size: cover;
  height: 100%;
  width: 100%;
  position: fixed;
  filter: blur(8px);
  -webkit-filter: blur(8px);
  -moz-filter: blur(8px);
  -o-filter: blur(8px);
  -ms-filter: blur(8px);
}
.body {
  height: 100%;
  width: 100%;
  position: fixed;
}
#content {
  height: 500px;
  width: 600px;
  /* background-color: skyblue; */
  left: 50%;
  top: 50%;
  margin-left: -300px;
  margin-top: -250px;
  position: relative;
}
#son {
  width: 300px;
  height: 200px;
  /* background-color: green; */
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -150px;
  margin-top: -100px;
}
#input {
  height: 30px;
  width: auto;
  position: relative;
  margin-top: 30px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
}
</style>